<div class="uimssVarieties" style="height: 100%;width:100%;overflow:auto;position: relative;">
    <div class="button-group-head" style="">
        <span class="hrp-btn hrp-btn-add" id="openDialog"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        <span  class="hrp-btn hrp-btn-refresh"><i class="fa fa-refresh" style="padding-right: 4px;"></i>刷新</span>
    </div>
    <div>
        <table id="dg" class="easyui-datagrid" style="width:100%;">
            <!--<thead>-->
            <!--<tr>-->
            <!--<th  width="15%">Item ID(15%)</th>-->
            <!--<th  width="15%">Product(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th  width="15%">List Price(15%)</th>-->
            <!--<th width="15%">List Price(15%)</th>-->
            <!--</tr>-->
            <!--</thead>-->
        </table>
    </div>

    <div id="editActionDialog"  class="ss-dialog" style="width:600px;height: 260px;margin-top: -300px;margin-top: -230px;">
        <span class="ss-dialog-close" style="">X</span>
        <div class="ss-dialog-head" style="">
            添加
        </div>
        <div class="ss-dialog-content">
            <div class="row" style="height: 60px;">
                <input type="hidden" id="idkey" value="-1"/>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">收款日期</span>
                <span style="width:35%;float:left;padding-top: 10px;"><input id="sendTime" type="text" value="0" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">打款方:</span>
                <span style="width:35%;float:left;padding-top: 10px;"><input  id="receiverId" type="text"  style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>

            </div>
            <div class="row" style="height: 60px;">
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">收款金额:</span>
                <span style="width:35%;float:left;"><input  id="money" type="text" placeholder="单价" value="0"  style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>
                <span style="width:15%;height:60px;line-height:60px;float:left;text-align: center;">备注:</span>
                <span style="width:35%;float:left;"><input  id="memo" type="text" placeholder="备注" style="margin: 0;padding: 0;height:35px;margin-top:10px;border:1px solid #ccc;box-shadow: 1px 1px 1px #eee;width:100%;" /></span>

            </div>
        </div>
        <div  class="ss-dialog-head" style="">
            <span class="hrp-btn hrp-btn-delete" style="float: right;" id="btn-cancel"><i class="fa fa-close" style="padding-right: 4px;"></i>取消</span>
            <span class="hrp-btn hrp-btn-add" style="float: right;" id="btn-save"><i class="fa fa-plus" style="padding-right: 4px;"></i>添加</span>
        </div>
    </div>
    <div id="mask-model" class="mask-model" style=""></div>


</div>


<script type="text/javascript">

    var dHeight = $(".uimssVarieties").height()-42;

    var UserIndexPage={
        tableName:"UIMSS_SUPPLIERINFO",
        editPriceFlag:false,
        init:function () {
            this.initGrid();
            this.initEvnets();
            this.initCombox();
        },
        initVarietiesComBox:function (id) {
            $('#varietiesId').combobox({
                url:"common/getUimssVarietiesDropList",
                queryParams: {
                    "id": id
                },
                valueField:'id',
                textField:'text',
                width:200,
                panelHeight:200,
                onSelect:function (record) {
                    if(UserIndexPage.editPriceFlag==false){
                        $("#price").val(record.value);
                    }
                },
                onLoadSuccess:function () {

                }
            });
        },
        initSupplierComBox:function (id) {
            $('#supplierId').combobox({
                url:"common/getUimssSupplierDropList",
                queryParams: {
                    "id": id
                },
                valueField:'id',
                textField:'text',
                width:200,
                panelHeight:200,
                onSelect:function (record) {

                },
                onLoadSuccess:function () {

                }
            });
        },
        initReceiverCombox:function (id) {
            $('#receiverId').combobox({
                url:"common/getUimssReceiverDropList",
                queryParams: {
                    "id": id
                },
                valueField:'id',
                textField:'text',
                width:200,
                panelHeight:200,
                onSelect:function (record) {

                },
                onLoadSuccess:function () {

                }
            });
        },
        initCombox:function () {

            var that= this;
            $('#sendTime').datebox({
                formatter : function(date){

                    //var date = new Date();
                    var year = date.getFullYear();
                    var month = date.getMonth() + 1;
                    var day = date.getDate();
                    var hour = date.getHours();
                    month = month < 10 ? '0' + month : month;
                    day = day < 10 ? '0' + day : day;
                    hour = hour < 10 ? '0' + hour : hour;
                    return year + "-" + month + "-" + day ;
                },
                parser:function (s) {
                    s = s.replace(/\s+/,' ');//解决格式字符串中多个空格拼接在Firefox中无法兼容的问题
                    var t = Date.parse(s);
                    if (!isNaN(t)){
                        return new Date(t);
                    } else {
                        return new Date(s + ":00");
                    }
                },
                onSelect:function (date) {

                }
            });

            $('#sendTime').datebox('setValue', that.formatterDate(new Date()));
        },
        initEvnets:function () {
            var that = this;
            $(window).resize(function () {
                $('#dg').datagrid("resize")
            })
            
            $(".hrp-btn-refresh").on("click",function () {
                that.initGrid();
            })
            
            $("#openDialog").on("click",function () {
                $("#idkey").val("-1");
                UserIndexPage.editPriceFlag=false;

                var receiverId  = localStorage.getItem("receiverId");
                if(receiverId == null || receiverId=='' ) {
                    receiverId=-1;
                }
                
                that.initReceiverCombox(receiverId);

                $('#editActionDialog').slideDown(300);
                $("#mask-model").slideDown(300);
            })

            $(".ss-dialog-close").on("click",function () {
                $('#editActionDialog').slideUp(300);
                $("#mask-model").slideUp(300);
            })

            $("#btn-save").on("click",function () {
                that.saveData();
            })

            $("#btn-cancel").on("click",function () {
                $('#editActionDialog').slideUp(300);
                $("#mask-model").slideUp(300);
            })

            //修改
            $(".uimssVarieties").on("click",".btn-edit",function () {


                UserIndexPage.editPriceFlag=true;


                var id = $(this).attr("data-id");
                var receiverTime = $.trim($(this).attr("data-receiverTime"));
                var receiverId = $.trim($(this).attr("data-receiverId"));
                var memo = $.trim($(this).attr("data-memo"));
                var money = $.trim($(this).attr("data-money"));

                $("#idkey").val(id);
                $('#sendTime').datebox('setValue', receiverTime);

                that.initReceiverCombox(receiverId);
                $("#memo").val(memo);
                $("#money").val(money);



                //$(".self-radio[data-value='"+tybz+"']").click()
                $('#editActionDialog').slideDown(300);
                $("#mask-model").slideDown(300);
                //that.editKhzb()
            })
        },
        saveData:function () {
            var that = this;
            var receiverTime = $('#sendTime').datebox('getValue');


            var receiverId = $('#receiverId').combobox('getValue');
            localStorage.setItem("receiverId",receiverId);
            var receiverName = $('#receiverId').combobox('getText');

            var money = $.trim($("#money").val());
            if(!that.checkNumber(money)){
                $.messager.show({title: '提示', msg: '收款金额数据不合法', timeout: 1000, showType: 'slide'});
                return;
            }
            var memo = $.trim($("#memo").val());

            $.post("receiveMoney/saveReceiveMoneyRecordData", {
                "id":$("#idkey").val(),
                "receiverTime":receiverTime,
                "receiverId":receiverId,
                "receiverName":receiverName,
                "money":money,
                "memo":memo
            }, function (result) {
                if (result.status == 200) {
                    $('#editActionDialog').slideUp(300);
                    $("#mask-model").slideUp(300);
                    that.initGrid();
                    $.messager.show({title: '提示', msg: '保存成功', timeout: 1000, showType: 'slide'});
                } else {
                    $.messager.show({title: '提示', msg: '保存失败', timeout: 1000, showType: 'slide'});
                }
            })
        },
        //得到当前日期
        formatterDate : function(date,type) {
            var day = date.getDate() > 9 ? date.getDate() : "0" + date.getDate();
            var month = (date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : "0" + (date.getMonth() + 1);
            return date.getFullYear() + '-' + month + '-' + day;

        },
        //验证字符串是否是数字
        checkNumber:function(theObj) {
            var reg = /^[0-9]+.?[0-9]*$/;
            if (reg.test(theObj)) {
                return true;
            }
            return false;
        },
        initGrid:function () {
            $('#dg').datagrid({
                url: "receiveMoney/getReceiveMoneyRecordByPage",
                queryParams: {
                    tableName: UserIndexPage.tableName
                },
                pagination: true,
                singleSelect: true,
                height:dHeight,   //表格高度，可指定高度，可自动
                pageNumber: 1,
                pageSize: 15,
                pageList: [15, 30],
                fitColumns:true,
                loadMsg: "正在加载数据",
                nowrap: false,
                striped: true,  //奇偶行是否使用不同的颜色
                columns:[
                    [
                        {field:'id',title:'编号',width:"10%"},
                        {field:'receiverTime',title:'收款日期',width:"20%"},
                        {field:'receiverName',title:'收款方名称',width:"20%"},
                        {field:'money',title:'收款金额',width:"20%"},
                        {field:'memo',title:'备注',width:"20%"},
                        {
                            field: 'edit', title: '操作', width: "10%",
                            formatter: function (value, row, index) {
                                return "<a class='btn-edit' href='#' data-id='"+row.id+"'  data-receiverTime='"+row.receiverTime+"'  data-receiverId='"+row.receiverId+"'  data-money='"+row.money+"'  data-memo='"+row.memo+"' >修改</a>"
                            }
                        }
                    ]
                ]
            });

        }
    }
    $(function () {
        UserIndexPage.init();
    })
</script>